package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.YyPatriarchMapper;
import com.ruoyi.system.domain.YyPatriarch;
import com.ruoyi.system.service.IYyPatriarchService;
import com.ruoyi.common.core.text.Convert;

/**
 * 家长Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-17
 */
@Service
public class YyPatriarchServiceImpl implements IYyPatriarchService
{
    @Autowired
    private YyPatriarchMapper yyPatriarchMapper;

    @Autowired
    private SysUserServiceImpl sysUserService;

    /**
     * 查询家长
     *
     * @param id 家长主键
     * @return 家长
     */
    @Override
    public YyPatriarch selectYyPatriarchById(Long id)
    {
        return yyPatriarchMapper.selectYyPatriarchById(id);
    }

    /**
     * 查询家长列表
     *
     * @param yyPatriarch 家长
     * @return 家长
     */
    @Override
    public List<YyPatriarch> selectYyPatriarchList(YyPatriarch yyPatriarch)
    {
        return yyPatriarchMapper.selectYyPatriarchList(yyPatriarch);
    }

    /**
     * 新增家长
     *
     * @param yyPatriarch 家长
     * @return 结果
     */
    @Override
    public int insertYyPatriarch(YyPatriarch yyPatriarch, SysUser sysUser)
    {
        //新增 系统用户
        sysUser.setStatus("0");
        Long[] array = {4L};
        sysUser.setRoleIds(array);
        sysUserService.insertUser(sysUser);
        yyPatriarch.setUserId(sysUser.getUserId());
        return yyPatriarchMapper.insertYyPatriarch(yyPatriarch);
    }

    /**
     * 修改家长
     *
     * @param yyPatriarch 家长
     * @return 结果
     */
    @Override
    public int updateYyPatriarch(YyPatriarch yyPatriarch)
    {
        return yyPatriarchMapper.updateYyPatriarch(yyPatriarch);
    }

    /**
     * 批量删除家长
     *
     * @param ids 需要删除的家长主键
     * @return 结果
     */
    @Override
    public int deleteYyPatriarchByIds(String ids)
    {
        return yyPatriarchMapper.deleteYyPatriarchByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除家长信息
     *
     * @param id 家长主键
     * @return 结果
     */
    @Override
    public int deleteYyPatriarchById(Long id)
    {
        return yyPatriarchMapper.deleteYyPatriarchById(id);
    }
}
